package zozopo.warehouse.report;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import zozopo.background.operator.operations.OperatorTB;
import zozopo.background.operator.operations.OperatorlimitedTB;

import zozopo.warehouse.operations.GoodsOS;
import zozopo.warehouse.operations.PurchaseOS;
import zozopo.warehouse.operations.PurchaselistOS;
import zozopo.warehouse.operations.ReceiptlistOS;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class CostReportAction extends ActionSupport implements Action,SessionAware{
	private String limitedCode = "REPORT.COST";
	//传入参数
	
	//分页参数
	
	
	//传出参数
	
	
	private Map<String,Double> sumPorfitMap;
	private Map<String,Double> avgPorfitMap;
	private Map<String,Double> salesAmountMap;
	private Map<String,Double> purchaselistTotalMap;
	private Map<String,Integer> countNumMap;
	
	private double warehouseCost;
	
	private Map<Object, Object> session;
	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}
	public String execute(){
		
		
		
		ReceiptlistOS receiptlistOS = new ReceiptlistOS();
		
		PurchaselistOS purchaselistOS = new PurchaselistOS(receiptlistOS.getConn());
		
		GoodsOS goodsOS = new GoodsOS(receiptlistOS.getConn());
		sumPorfitMap = receiptlistOS.getSumPorfitMap();
		salesAmountMap = receiptlistOS.getSalesAmountMap();
		countNumMap  = receiptlistOS.getCountNumMap();
		purchaselistTotalMap = purchaselistOS.getTotalMap();
		avgPorfitMap = receiptlistOS.getAveragePorfitMap();
		
		
		
		warehouseCost = goodsOS.getCost();
		
		receiptlistOS.releaseConnection();
		
		return SUCCESS;
		
	}
	
	
	public void validate() {
		//权限处理
		OperatorTB operator = (OperatorTB)session.get("operatorInfo"); 
	
		if(operator == null){
			addFieldError("errormessage",getText("operator.timeoutornotlogin"));
			return ; 
		} 
		
		//用户权限
		Map<String,OperatorlimitedTB> operatorlimitedMap = (Map<String,OperatorlimitedTB>)session.get("operatorlimitedMap");
		
		if(operatorlimitedMap.get(limitedCode) == null){
			addFieldError("errormessage","用户没有权限.");
			return;
		}
		
	}
	
	

	public double getWarehouseCost() {
		return warehouseCost;
	}
	public void setWarehouseCost(double warehouseCost) {
		this.warehouseCost = warehouseCost;
	}
	
	public String getLimitedCode() {
		return limitedCode;
	}
	public void setLimitedCode(String limitedCode) {
		this.limitedCode = limitedCode;
	}
	public Map<String, Double> getSumPorfitMap() {
		return sumPorfitMap;
	}
	public void setSumPorfitMap(Map<String, Double> sumPorfitMap) {
		this.sumPorfitMap = sumPorfitMap;
	}
	public Map<String, Double> getSalesAmountMap() {
		return salesAmountMap;
	}
	public void setSalesAmountMap(Map<String, Double> salesAmountMap) {
		this.salesAmountMap = salesAmountMap;
	}
	public Map<String, Double> getPurchaselistTotalMap() {
		return purchaselistTotalMap;
	}
	public void setPurchaselistTotalMap(Map<String, Double> purchaselistTotalMap) {
		this.purchaselistTotalMap = purchaselistTotalMap;
	}
	public Map<String, Integer> getCountNumMap() {
		return countNumMap;
	}
	public void setCountNumMap(Map<String, Integer> countNumMap) {
		this.countNumMap = countNumMap;
	}
	public Map<String, Double> getAvgPorfitMap() {
		return avgPorfitMap;
	}
	public void setAvgPorfitMap(Map<String, Double> avgPorfitMap) {
		this.avgPorfitMap = avgPorfitMap;
	}
	
	

}
